#include "reslution.h"
#include <QTextStream>
#include <QFile>
#include <QHostAddress>
#include <QRegExpValidator>
#include "../CheckInfor/DataBase/databasetool.h"
#include <iostream>
#include <QHostInfo>

namespace Yzty
{
    Reslution* Reslution::_instance=nullptr;

    Reslution* Reslution::GetInstance(QObject *parent)
    {
        if(Reslution::_instance==nullptr)
            Reslution::_instance=new Reslution(parent);
        return Reslution::_instance;
    }

    QStringList Reslution::GetFromString(const QString& cmd){
        FILE* fp=popen(cmd.toStdString().c_str(),"r");
        if(fp==nullptr)
            return {};
        QTextStream fstream(fp);
        QStringList ret=fstream.readAll().split('\n');
        fclose(fp);
        return ret;
    }

    void Reslution::ExecuteCmd(const QString &cmd)
    {
        system(cmd.toLocal8Bit());
    }

    Reslution::Reslution(QObject *parent) : QObject(parent)
    {

    }

    Reslution::~Reslution()
    {

    }

    QVector<BaceInfor*> Reslution::GetSysShareDirInforFromCmd()            //系统共享安全
    {
        #ifdef LINUX
     //              QString cmd="grep -v ^\\$ /etc/samba/smb.conf |grep -v ^\\# |grep -v ^\\;";
                   QString cmd="grep -v ^\\$ /etc/samba/smb.conf";
             #else
                   QString cmd="grep -v ^\\$ /etc/samba/smb.conf |grep -v ^\\# |grep -v ^\\;";
             #endif
                   QVector<BaceInfor*> result;
                   FILE* fp=popen(cmd.toLocal8Bit(),"r");          //获取命令行输出
                   if(fp==nullptr)
                       return result;
                   QTextStream fstream(fp);
                   QString infor=fstream.readAll();

                   QRegularExpression re("\\[.{1,}\\]");// 构建正则表达式
                   QRegularExpressionMatch match; //定义匹配对象
                   QString tmp,tmp1;
              //     QStringList temp=infor.split(QRegExp("[\r\n]"),QString::SkipEmptyParts);
                   int index=0,start,end,flag=0;//定义匹配位置
                         do{
                           match = re.match(infor,index);//执行匹配
                           if(match.hasMatch()){
                               start=match.capturedStart();
                               end=match.capturedEnd();
                               tmp=match.captured(0);
                               QStringList temp1=infor.mid(start).split('\n');
                               SysShareDirInfor* shareInfo=new SysShareDirInfor(uint16_t(SecurityToolCode::SysShare));
                                for(QString& tmp1:temp1){
                                  // QStringList tmp2=tmp1.simplified().split(' ');
                                   tmp1=tmp1.simplified();
                                   if(tmp1.startsWith('[')){
                                       if(flag){
                                           flag=0;
                                           break;
                                       }
                                       else{
                                           shareInfo->_infors[SysShareDirInfor::SHARENAME]=tmp1.mid(1,tmp1.size()-2);
                                           flag=1;
                                       }
                                   }
                                   if(flag){
                                       if(tmp1.startsWith("path"))
                                           shareInfo->_infors[SysShareDirInfor::ROUTE]=tmp1.mid(tmp1.indexOf("=")+1);
                                       if(tmp1.startsWith("comment"))
                                           shareInfo->_infors[SysShareDirInfor::DESCRIP]=tmp1.mid(tmp1.indexOf("=")+1);
                                       if(tmp1.startsWith("create"))
                                           shareInfo->_infors[SysShareDirInfor::PERM]=tmp1.mid(tmp1.indexOf("=")+1);
                                   }
                               }
                               if(shareInfo->_infors[SysShareDirInfor::ROUTE]=="")
                                   shareInfo->_infors[SysShareDirInfor::ROUTE]="SystemPath";
                               if(shareInfo->_infors[SysShareDirInfor::DESCRIP]=="")
                                   shareInfo->_infors[SysShareDirInfor::DESCRIP]="******";
                               if(shareInfo->_infors[SysShareDirInfor::PERM]=="")
                                   shareInfo->_infors[SysShareDirInfor::PERM]="Default";
                               result.push_back(shareInfo);
                               index=end;
                           }
                           else
                               break;
                         }while(index<infor.length());

                   return result;
    }

    QVector<BaceInfor*> Reslution::GetNetLoginInforFromCmd()               //远程登陆检查
    {

        //远程登陆检查
        bool flag = false; //22端口是否被使用标记
        QString ssh_route="/etc/ssh/sshd_config";
        QString vnc_cmd="ps -ef |grep vnc|grep -v grep";
        QVector<BaceInfor*> result;
        QFile file(ssh_route);
        file.open(QIODevice::ReadOnly | QIODevice::Text);
        QTextStream fstream(file.readAll());
        QStringList infors = fstream.readAll().split('\n');
        NetLoginInfor * item1 = new NetLoginInfor(uint16_t(SecurityToolCode::NetLogin));
        NetLoginInfor * item2 = new NetLoginInfor(uint16_t(SecurityToolCode::NetLogin));
        NetLoginInfor * item3 = new NetLoginInfor(uint16_t(SecurityToolCode::NetLogin));
        NetLoginInfor * item4 = new NetLoginInfor(uint16_t(SecurityToolCode::NetLogin));
        //初始化设置相关检查的默认值
        item1->_infors[NetLoginInfor::FORLOGIN]="空密码不能通过SSH登陆";
        item1->_infors[NetLoginInfor::STATE]="是";
        item2->_infors[NetLoginInfor::FORLOGIN]="开启了Root用户SSH登陆";
        item2->_infors[NetLoginInfor::STATE]="否";
        item3->_infors[NetLoginInfor::FORLOGIN]="SSH使用了22号端口";
        item3->_infors[NetLoginInfor::STATE]="是";
        item4->_infors[NetLoginInfor::FORLOGIN]="未启用了VNC服务";
        item4->_infors[NetLoginInfor::STATE]="是";
        //检查开始
        //检查22号端口
        QVector<BaceInfor*> tempinfor = this->GetNetPortInforFromCmd();
        for(const Yzty::BaceInfor* infor:tempinfor){
            const Yzty::NetPortInfor* temp=dynamic_cast<const Yzty::NetPortInfor*>(infor);
            if(temp->_infors[Yzty::NetPortInfor::LOCALPORT] == "22") {
                flag = true;
            }
        }
        for(QString infor:infors)
        {
            if(infor=="")
                continue;
            else if(infor=="PermitEmptyPasswords yes")
                item1->_infors[NetLoginInfor::STATE]="否";
            else if(infor=="PermitRootLogin yes")
                item2->_infors[NetLoginInfor::STATE]="是";
        }

        if(flag)
            item3->_infors[NetLoginInfor::STATE]="是";
        else
            item3->_infors[NetLoginInfor::STATE]="否";
        //检查vnc服务是否开启
        FILE* fp=popen(vnc_cmd.toLocal8Bit(),"r");
        if(fp==nullptr)
            return result;
        QTextStream fstream1(fp);
        QStringList infors1 = fstream1.readAll().split('\n');
        for(QString infor:infors1)
        {
            if(infor=="")
                continue;
            if(infor!="")
            {
                item4->_infors[NetLoginInfor::STATE]="否";
                break;
            }
        }
        result.push_back(item1);
        result.push_back(item2);
        result.push_back(item3);
        result.push_back(item4);
        file.close();
        return result;
    }

    QVector<BaceInfor*> Reslution::GetSysUpdateInforFromCmd()              //系统升级文件
    {
        QString infors_cmd="apt list --installed|grep \"可升级至\"";//中间部分为当前的软件信息，后面为升级信息
        QString update_cmd = "sudo apt-get update";
        system(update_cmd.toLocal8Bit());               //更新源
        QVector<BaceInfor*>result;
        FILE* fp=popen(infors_cmd.toLocal8Bit(),"r");
        if(fp==nullptr)
            return result;
        QTextStream fstream(fp);
        QStringList infors=fstream.readAll().split('\n');
        for(QString& infor:infors)
        {
            SysUpdateInfor * temp = new SysUpdateInfor(uint16_t(SecurityToolCode::SysUpdate));
            if(infor=="")
                continue;
            QStringList infors1=infor.simplified().split('/');
            if(infors1.size()>=1)
            temp->_infors[SysUpdateInfor::UPDATENAME]=infors1[0];
            QStringList infors2=infors1[1].simplified().split('[');
            QStringList infors3=infors2[0].simplified().split(' ');
            temp->_infors[SysUpdateInfor::DESCRIP]="可从该版本升级："+infors3[1];
            QStringList infors4=infors2[1].simplified().split("：");
            temp->_infors[SysUpdateInfor::UPDATEVER]=infors4.last().replace("]","");
            result.push_back(temp);
            temp->_infors[SysUpdateInfor::PUBTIME]="未知";                    //bug
        }
        return result;
    }

    QVector<BaceInfor*> Reslution::GetNetPortInforFromCmd()                //系统开放端口
    {
        #ifdef LINUX
            QString cmd="sudo netstat -ntpl&&sudo netstat -nupl";
        #else
            QString cmd="sudo netstat -ntpl&&sudo netstat -nupl";
        #endif
        QVector<BaceInfor*> result;
        FILE* fp=popen(cmd.toLocal8Bit(),"r");
        if(fp==nullptr)
            return result;
        QTextStream fstream(fp);
        QStringList infors=fstream.readAll().split('\n');
        for(QString& infor:infors)
        {
            if(infor=="")//过滤空行
                continue;
            NetPortInfor *temp=new NetPortInfor(uint16_t(SecurityToolCode::NetPortInfor));
            if(infor.contains("tcp")||infor.contains("udp"))
            {
                QStringList inforss = infor.simplified().split(' ');
                temp->_infors[NetPortInfor::PROTO]=inforss[0];
                QStringList inforss1 = inforss[3].simplified().split(':');
                QStringList inforss2 = inforss[4].simplified().split(':');
                if(inforss[3].contains("::"))
                {
                    temp->_infors[NetPortInfor::LOCALIP]="::";
                    temp->_infors[NetPortInfor::LOCALPORT]=inforss1.last();
                }
                else
                {
                    temp->_infors[NetPortInfor::LOCALIP]=inforss1[0];
                    temp->_infors[NetPortInfor::LOCALPORT]=inforss1.last();
                }
                if(inforss[4].contains("::"))
                {
                    temp->_infors[NetPortInfor::FOREIGNIP]="::";
                    temp->_infors[NetPortInfor::FOREIGNPORT]=inforss2.last();
                }
                else
                {
                    temp->_infors[NetPortInfor::FOREIGNIP]=inforss1[0];
                    temp->_infors[NetPortInfor::FOREIGNPORT]=inforss2.last();
                }
                QStringList inforss3 = infor.simplified().split('/');       //PID项和PNAME之间可能有空格,重新拆分
                QStringList inforss4 = inforss3[0].simplified().split(' ');
                if(inforss.last()=="-")
                {
                    temp->_infors[NetPortInfor::PID]="-";
                    temp->_infors[NetPortInfor::PNAME]="-";
                }
                else
                {

                    temp->_infors[NetPortInfor::PID]=inforss4.last();
                    temp->_infors[NetPortInfor::PNAME]=inforss3.last();
                }

                if(inforss4.size()<=6)
                    temp->_infors[NetPortInfor::PORTSTATE]="-";
                else
                    temp->_infors[NetPortInfor::PORTSTATE]=inforss4[5];
                result.push_back(temp);
            }
        }
        return result;
    }

    QVector<BaceInfor*> Reslution::GetAccountSecInforFromCmd()             //账户安全配置
    {
        //缺密码复杂度
        QString pwd_cmd = "chage -l `whoami`";
        QString guesst_route = "/etc/lightdm/lightdm.conf";
        QString pwd_route = "/etc/pam.d/common-password";
        QVector<BaceInfor*> result;
        AccountSecInfor *item[6];
        for(int i=0;i<6;i++)
        {
            item[i] = new AccountSecInfor(uint16_t(SecurityToolCode::AccountSec));
        }
        item[0]->_infors[AccountSecInfor::ITEMS] = "强制密码历史";
        item[1]->_infors[AccountSecInfor::ITEMS] = "guesst账户状态";
        item[2]->_infors[AccountSecInfor::ITEMS] = "密码最长使用期限";
        item[3]->_infors[AccountSecInfor::ITEMS] = "密码最短使用期限";
        item[4]->_infors[AccountSecInfor::ITEMS] = "密码最小长度";
        item[5]->_infors[AccountSecInfor::ITEMS] = "密码复杂度检测";
        item[0]->_infors[AccountSecInfor::DESCRIP] = "记住0个密码";
        item[4]->_infors[AccountSecInfor::DESCRIP] = "0";
        item[5]->_infors[AccountSecInfor::DESCRIP]="不允许";
        QFile file1(guesst_route);
        QFile file2(pwd_route);
        FILE *file3=popen(pwd_cmd.toLocal8Bit(),"r");
        file1.open(QIODevice::ReadOnly | QIODevice::Text);
        file2.open(QIODevice::ReadOnly | QIODevice::Text);
        QTextStream stream1(file1.readAll());
        QTextStream stream2(file2.readAll());
        QTextStream stream3(file3);
        //1,5,6项
        QStringList infors = stream2.readAll().split('\n');
        for(QString infor:infors)
        {
            if(infor=="")
                continue;
            if(infor.contains("pam_unix.so")&&infor.contains("remember"))
            {
                QStringList inforss1 = infor.simplified().split(' ');
                for(QString infor1:inforss1)
                {
                    if(infor1.contains("remember"))
                    {
                        item[0]->_infors[AccountSecInfor::DESCRIP] = infor1.simplified().split('=').last();
                        break;
                    }
                }
            }
            if(infor.contains("pam_cracklib.so")&&infor.contains("minlen"))
            {
                item[5]->_infors[AccountSecInfor::DESCRIP]="允许";
                QStringList inforss1 = infor.simplified().split(' ');
                for(QString infor1:inforss1)
                {
                    if(infor1.contains("minlen"))
                    {
                        item[4]->_infors[AccountSecInfor::DESCRIP] = QString::number(infor1.simplified().split('=').last().toInt()-1);
                        break;
                    }
                }
            }
        }
        //2项
        infors = stream1.readAll().split('\n');
        for(QString infor:infors)
        {
            if(infor=="")//过滤空行
                continue;
            if(infor=="allow-guest=false")
            {
                item[1]->_infors[AccountSecInfor::DESCRIP]="禁止";
                break;
            }

            else
                item[1]->_infors[AccountSecInfor::DESCRIP]="允许";
        }
        //3-4项
        infors = stream3.readAll().split('\n');
        if(infors.size()<=6)
        {
            item[2]->_infors[AccountSecInfor::DESCRIP]="-";
            item[3]->_infors[AccountSecInfor::DESCRIP]="-";
        }
        else
        {
            item[2]->_infors[AccountSecInfor::DESCRIP]=infors[5].simplified().split("：").last();
            item[3]->_infors[AccountSecInfor::DESCRIP]=infors[4].simplified().split("：").last();
        }
        for(int i=0;i<6;i++)
        {
            result.push_back(item[i]);
        }
        file1.close();
        file2.close();
        return result;
    }

    QVector<BaceInfor*> Reslution::GetPwdConfigInforFromCmd()              //密码策略配置
    {
        //未判断是否安装插件：pam_tally2.so，pam_cracklib.so
        //最后一项未写
        QString login_route="/etc/login.defs";
        QString pwd_route="/etc/pam.d/common-password";
        QString pwdcount_route="/etc/pam.d/login";
        QVector<BaceInfor*>result;
        PwdConfigInfor * item[10];
        for(int i=0;i<10;i++)//初始化条目
        {
            item[i]=new PwdConfigInfor(uint16_t(SecurityToolCode::PwdConfig));
            item[i]->_infors[PwdConfigInfor::DESCRIP]="无限制";
        }
        item[0]->_infors[PwdConfigInfor::ITEMS]="密码最大有效期";
        item[1]->_infors[PwdConfigInfor::ITEMS]="是否可修改密码，0可修改，非0为多少天后可以修改";
        item[2]->_infors[PwdConfigInfor::ITEMS]="密码失效前多少天在用户登陆的时通知用户修改密码";
        item[3]->_infors[PwdConfigInfor::ITEMS]="密码最小长度";
        item[4]->_infors[PwdConfigInfor::ITEMS]="密码中必须包含多少个数字";
        item[5]->_infors[PwdConfigInfor::ITEMS]="密码中必须包含多少个大写字母";
        item[6]->_infors[PwdConfigInfor::ITEMS]="密码中必须包含多少个小写字母";
        item[7]->_infors[PwdConfigInfor::ITEMS]="密码中必须包括多少个特殊字符(数字，字母除外)";
        item[8]->_infors[PwdConfigInfor::ITEMS]="尝试输入密码的次数";
        item[9]->_infors[PwdConfigInfor::ITEMS]="密码包含字符串的个数";
        //1-3项
        QFile file1(login_route);
        file1.open(QIODevice::ReadOnly | QIODevice::Text);
        QTextStream fstream(file1.readAll());
        QStringList infors = fstream.readAll().split('\n');
        for(QString infor:infors)
        {
            QStringList temp = infor.simplified().split(' ');
            if(temp.size()>=2)
            {
                if(temp[0]=="PASS_MAX_DAYS")
                    item[0]->_infors[PwdConfigInfor::DESCRIP]=temp[1];//最大有效期
                else if(temp[0]=="PASS_MIN_DAYS")
                    item[1]->_infors[PwdConfigInfor::DESCRIP]=temp[1];//最小可修改
                else if(temp[0]=="PASS_WARN_AGE")
                    item[2]->_infors[PwdConfigInfor::DESCRIP]=temp[1];//警告天数
            }

        }
        //4-8项
        QFile file2(pwd_route);
        file2.open(QIODevice::ReadOnly | QIODevice::Text);
        QTextStream fstream2(file2.readAll());
        infors = fstream2.readAll().split('\n');
        for(QString  infor:infors)//行
        {
            QStringList temp = infor.simplified().split(' ');
            if(temp.size()>=3&&temp[2]=="pam_cracklib.so")//找到指定行
            {
                for(QString temp1:temp)//块
                {
                    if(temp1.contains("minlen",Qt::CaseSensitive))          //长度
                    {
                        QStringList temp2 = temp1.simplified().split('=');
                        item[3]->_infors[PwdConfigInfor::DESCRIP]=QString::number(temp2[1].toInt()-1);
                    }
                    else if(temp1.contains("dcredit",Qt::CaseSensitive))    //数字
                    {
                        QStringList temp2 = temp1.simplified().split("=-");
                        item[4]->_infors[PwdConfigInfor::DESCRIP]=temp2[1];
                    }
                    else if(temp1.contains("ucredit",Qt::CaseSensitive))    //大写字母
                    {
                        QStringList temp2 = temp1.simplified().split("=-");
                        item[5]->_infors[PwdConfigInfor::DESCRIP]=temp2[1];
                    }
                    else if(temp1.contains("lcredit",Qt::CaseSensitive))    //小写字母
                    {
                        QStringList temp2 = temp1.simplified().split("=-");
                        item[6]->_infors[PwdConfigInfor::DESCRIP]=temp2[1];
                    }
                    else if(temp1.contains("ocredit",Qt::CaseSensitive))    //特殊符号
                    {
                        QStringList temp2 = temp1.simplified().split("=-");
                        item[7]->_infors[PwdConfigInfor::DESCRIP]=temp2[1];
                    }
                }
                break;
            }
        }
        //9项
        QFile file3(login_route);
        file3.open(QIODevice::ReadOnly | QIODevice::Text);
        QTextStream fstream3(file3.readAll());
        infors = fstream3.readAll().split('\n');
        for(QString infor:infors)
        {
            QStringList temp = infor.simplified().split(' ');
            if(temp.size()>=3&&temp[2]=="pam_tally2.so")//找到指定行
            {
                for(QString temp1:temp)
                {
                    if(temp1.contains("deny",Qt::CaseSensitive))//次数
                    {
                        QStringList temp2 = temp1.simplified().split('=');
                        item[8]->_infors[PwdConfigInfor::DESCRIP]=temp2[1];
                    }
                }
            }
        }
        item[9]->_infors[PwdConfigInfor::DESCRIP]="未知";                                     //bug
        for(int i=0;i<10;i++)
        result.push_back(item[i]);
        file1.close();
        file2.close();
        file3.close();
        return result;
    }

    QVector<BaceInfor*> Reslution::GetNetConfigFromCmd()                   //网络安全配置
    {
        QString sctpcmd="lsmod |grep sctp";
        QString tipccmd="lsmod |grep tipc";
        QString icmp_acc_cmd="/proc/sys/net/ipv4/conf/default/accept_redirects";
        QString icmp_igo_cmd="/proc/sys/net/ipv4/icmp_echo_ignore_all";
        QString icmp_send_cmd="/proc/sys/net/ipv4/conf/default/send_redirects";
        QVector<BaceInfor*> result;
        NetConfig* login[5];
        for(int i=0;i<5;i++)
                login[i]=new NetConfig(uint16_t(SecurityToolCode::NetConfig));
        login[0]->_infors[NetConfig::ITEMS]="SCTP协议";
        login[1]->_infors[NetConfig::ITEMS]="TIPC协议";
        login[2]->_infors[NetConfig::ITEMS]="接受ICMP重定";
        login[3]->_infors[NetConfig::ITEMS]="ICMP回应忽视";
        login[4]->_infors[NetConfig::ITEMS]="发送ICMP重定向";
        FILE* fp=popen(sctpcmd.toLocal8Bit(),"r");                      //1项
        if((new QTextStream(fp))->readLine()=="")
            login[0]->_infors[NetConfig::DESCRIPTION]="不支持";
        else
             login[0]->_infors[NetConfig::DESCRIPTION]="支持";
        fclose(fp);
        FILE* fp1=popen(sctpcmd.toLocal8Bit(),"r");                     //2项
        if((new QTextStream(fp1))->readLine()=="")
            login[1]->_infors[NetConfig::DESCRIPTION]="不支持";
        else
            login[1]->_infors[NetConfig::DESCRIPTION]="支持";
        fclose(fp1);
        QFile file(icmp_acc_cmd);                                       //3项
        file.open(QIODevice::ReadOnly | QIODevice::Text);
        QString t = file.readLine();
        if(t[0]=='0')
            login[2]->_infors[NetConfig::DESCRIPTION]="禁止";
        else
            login[2]->_infors[NetConfig::DESCRIPTION]="允许";
        file.close();
        QFile file1(icmp_igo_cmd);                                      //4项
        file1.open(QIODevice::ReadOnly | QIODevice::Text);
        t = file1.readLine();
        if(t[0]=='0')
            login[3]->_infors[NetConfig::DESCRIPTION]="禁止";
        else
            login[3]->_infors[NetConfig::DESCRIPTION]="允许";
        file1.close();
        QFile file2(icmp_send_cmd);                                     //5项
        file2.open(QIODevice::ReadOnly | QIODevice::Text);
        t = file2.readLine();
        if(t[0]=='0')
            login[4]->_infors[NetConfig::DESCRIPTION]="禁止";
        else
            login[4]->_infors[NetConfig::DESCRIPTION]="允许";
        file2.close();
        for(int i=0;i<5;i++)
            result.push_back(login[i]);
        return result;
    }

    QVector<BaceInfor*> Reslution::GetSecAuditInforFromCmd()               //安全审计配置
    {
        QString cmd = "sudo auditctl -l";
        QVector<BaceInfor*> result;
        FILE *fp = popen(cmd.toLocal8Bit(),"r");
        QTextStream stream(fp);
        QStringList infors = stream.readAll().split('\n');
        for(QString infor:infors)
        {
            SecAuditInfor *item = new SecAuditInfor(uint16_t(SecurityToolCode::SecAudit));
            item->_infors[SecAuditInfor::MODE]="ALL";
            if(infor=="")
                continue;
            QStringList inforss = infor.simplified().split(' ');
            if(inforss.first()=="-w")
            {
                item->_infors[SecAuditInfor::TYPE]="文件系统";
                item->_infors[SecAuditInfor::TACTIC]=inforss[1];
                for(int i=0;i<inforss.size();i++)
                {
                    if(inforss[i].contains("key"))
                    {
                        item->_infors[SecAuditInfor::MODE]=inforss[i].split('=').last();
                        break;
                    }
                }
                result.push_back(item);
            }
            else if(inforss.first()=="-a")
            {
                item->_infors[SecAuditInfor::TYPE]="系统调用";
                for(int i=0;i<inforss.size();i++)
                {
                    if(inforss[i].contains("-s",Qt::CaseInsensitive))//大小写不敏感
                    {
                        item->_infors[SecAuditInfor::TACTIC]=inforss[i+1];
                    }
                    else if(inforss[i].contains("key"))//取‘key=’后字符
                    {
                        item->_infors[SecAuditInfor::MODE]=inforss[i].split('=').last();
                    }
                }

                result.push_back(item);
            }
        }
        return result;
    }

    QVector<BaceInfor*> Reslution::GetSudoConfigInforFromCmd()             //sudo策略配置
    {
        QString config_route="sudo cat /etc/sudoers";
        QString username_cmd="whoami";
        FILE *fp =popen(username_cmd.toLocal8Bit(),"r");
        QTextStream namestream(fp);
        QString username=namestream.readAll().simplified();//获取当前用户名
        QVector<BaceInfor*>result;
        FILE *file = popen(config_route.toLocal8Bit(),"r");
        QTextStream stream(file);
        QStringList infors = stream.readAll().split('\n');
        SudoConfigInfor *item[3];
        for(int i=0;i<3;i++)
        {
            item[i]=new SudoConfigInfor(uint16_t(SecurityToolCode::SudoConfig));
            item[i]->_infors[SudoConfigInfor::DESCRIPTION]="需要验证管理员密码";
        }
        item[0]->_infors[SudoConfigInfor::TACTIC]="root用户sudo权限规范";
        item[1]->_infors[SudoConfigInfor::TACTIC]="允许管理组成员执行的sudo命令";
        item[2]->_infors[SudoConfigInfor::TACTIC]="当前用户sudo权限规范";
        for(QString infor:infors)
        {
            if(infor.size()>=8&&infor.startsWith("root",Qt::CaseSensitive))
            {
                QStringList temp = infor.simplified().split('=');
                if(!(temp[1]=="(ALL:ALL) ALL"||temp[1]=="(ALL) ALL"))
                    item[0]->_infors[SudoConfigInfor::DESCRIPTION]=temp[1];
                else
                    item[0]->_infors[SudoConfigInfor::DESCRIPTION]="无限制";
            }
            else if(infor.size()>=8&&infor.startsWith("%sudo",Qt::CaseSensitive))
            {
                QStringList temp = infor.simplified().split('=');
                if(!(temp[1]=="(ALL:ALL) ALL"||temp[1]=="(ALL) ALL"))
                    item[1]->_infors[SudoConfigInfor::DESCRIPTION]=temp[1];
                else
                    item[1]->_infors[SudoConfigInfor::DESCRIPTION]="无限制";
            }
            else if(infor.size()>=8&&infor.startsWith(username,Qt::CaseSensitive))
            {
                QStringList temp = infor.simplified().split('=');
                if(!(temp[1]=="(ALL:ALL) ALL"||temp[1]=="(ALL) ALL"))
                    item[2]->_infors[SudoConfigInfor::DESCRIPTION]=temp[1];
                else
                    item[2]->_infors[SudoConfigInfor::DESCRIPTION]="无限制";
            }
        }
        for(int i=0;i<3;i++)
            result.push_back(item[i]);
        return result;
    }

    QVector<BaceInfor*> Reslution::GetNetFireWallInforFromCmd()            //防火墙配置
    {
        QString icmproute="/proc/sys/net/ipv4/icmp_echo_ignore_all";
        QString ipstatusroute="/proc/sys/net/ipv4/ip_forward";
        QString guesstroute="/etc/lightdm/lightdm.conf";
        QString firewallcmd="systemctl status firewalld";
        QVector<BaceInfor*>result;

        NetFireWallInfor* items=new NetFireWallInfor(uint16_t(SecurityToolCode::NetFireWall));
        QFile file1(icmproute);
        file1.open(QIODevice::ReadOnly | QIODevice::Text);
        QString t = file1.readLine();
        items->_infors[NetFireWallInfor::ITEMS]="ICMP回应状态";
        if(t[0]=='0')
            items->_infors[NetFireWallInfor::DESCRIPTION]="允许";
        else
            items->_infors[NetFireWallInfor::DESCRIPTION]="禁止";
        result.push_back(items);

        items=new NetFireWallInfor(uint16_t(SecurityToolCode::NetFireWall));
        QFile file2(ipstatusroute);
        file2.open(QIODevice::ReadOnly | QIODevice::Text);
        t = file2.readLine();
        items->_infors[NetFireWallInfor::ITEMS]="IP转发状态";
        if(t[0]=='0')
            items->_infors[NetFireWallInfor::DESCRIPTION]="禁止";
        else
            items->_infors[NetFireWallInfor::DESCRIPTION]="允许";
        result.push_back(items);

        items=new NetFireWallInfor(uint16_t(SecurityToolCode::NetFireWall));
        QFile file3(guesstroute);
        file3.open(QIODevice::ReadOnly | QIODevice::Text);
        QTextStream fstream(file3.readAll());
        QStringList infors = fstream.readAll().split('\n');
        items->_infors[NetFireWallInfor::ITEMS]="Guesst账户状态";
        for(QString infor:infors)
        {
            if(infor=="")//过滤空行
                continue;
            if(infor=="allow-guest=false")
                items->_infors[NetFireWallInfor::DESCRIPTION]="禁止";
            else
                items->_infors[NetFireWallInfor::DESCRIPTION]="允许";
        }
        result.push_back(items);

        items=new NetFireWallInfor(uint16_t(SecurityToolCode::NetFireWall));
        FILE* fp=popen(firewallcmd.toLocal8Bit(),"r");
        if(fp==nullptr)
            return result;
        QTextStream fstream1(fp);
        QStringList tem = fstream1.readAll().split('\n');
        items->_infors[NetFireWallInfor::ITEMS]="防火墙已激活";
        items->_infors[NetFireWallInfor::DESCRIPTION]="否";
        for(QString infor:tem)
        {
            if(infor=="")
                continue;
            if(infor.contains("active (running)"))
            {
                items->_infors[NetFireWallInfor::DESCRIPTION]="是";
                break;
            }
        }
        result.push_back(items);
        file1.close();
        file2.close();
        file3.close();
        fclose(fp);
           return result;
    }

    QVector<BaceInfor*> Reslution::GetSysProcessInforFromCmd()             //系统进程信息
        {
            #ifdef LINUX
            QString cmd="ps -aux";
            #else
            QString cmd="ps -aux";
            #endif
            QVector<BaceInfor*> result;
            FILE* fp=popen(cmd.toLocal8Bit(),"r");
            if(fp==nullptr)
                return result;
            QTextStream fstream(fp);
            QStringList infors=fstream.readAll().split('\n');
            int count = infors.length();
            int n=0;
            for(QString& infor:infors)
            {
                n++;

                if(n>=count)
                    break;
                QStringList temp=infor.simplified().split(' ');
                QVector<QString> _infors;
                SysProcessInfor* proc=new SysProcessInfor(uint16_t(SecurityToolCode::SysProcess));
                if(temp[1]=="PID")
                    continue;

                proc->_infors[SysProcessInfor::PID]=temp[1];           //jinchengID
                proc->_infors[SysProcessInfor::NAME]=temp[10];       //jinchengmingcheng
                if(proc->_infors[SysProcessInfor::NAME].contains("C"))
                {
                    int first=temp[10].lastIndexOf("\\");       //从后面查找“\”的位置
                    QString t=temp[10].right(temp[10].length()-first-1);        //从右边截取
                    proc->_infors[SysProcessInfor::NAME]=t;
                    proc->_infors[SysProcessInfor::PATH]=temp[10];
                }
                if((temp[10].contains("/")&&temp[10].contains("[")&&temp[10].contains("_"))||temp[10].contains("[")||(temp[10].contains("_")&&proc->_infors[SysProcessInfor::NAME].contains("-")&&proc->_infors[SysProcessInfor::NAME].contains(".")))
                {
                    proc->_infors[SysProcessInfor::PATH]="system path";

                }
                else if(proc->_infors[SysProcessInfor::NAME].contains("_")&&proc->_infors[SysProcessInfor::NAME].contains("-"))
                {
                    int first=temp[10].lastIndexOf("/");       //从后面查找“/”的位置
                    QString t=temp[10].right(temp[10].length()-first-1);        //从右边截取
                    proc->_infors[SysProcessInfor::NAME]=t;
                }
                else
                {
                    int first=temp[10].lastIndexOf("/");       //从后面查找“/”的位置
                    QString t=temp[10].right(temp[10].length()-first-1);        //从右边截取
                    proc->_infors[SysProcessInfor::NAME]=t;
                    proc->_infors[SysProcessInfor::PATH]=temp[10];
                }


                result.push_back(proc);
            }
            return result;
        }


    QVector<BaceInfor*> Reslution::GetSysServerInforFromCmd()              //系统服务信息
    {
        QString systemctl_service_cmd="systemctl list-units --type service|grep -v UNIT";   //获取服务信息
        QString process_cmd="service bluetooth status|grep -v Warning|grep -v ^$";          //获取进程信息
        QString service_start_cmd="systemctl list-unit-files|grep enabled|grep .service";   //获取服务详细信息
        QVector<BaceInfor*> result;
        QMap<QString,QString> service_start;                                                //存放服务启动类型
        QString PID;
        FILE *fp1 = popen(systemctl_service_cmd.toLocal8Bit(),"r");
        FILE *fp2 = popen(service_start_cmd.toLocal8Bit(),"r");
        FILE *temp = nullptr;
        QTextStream stream1(fp1);
        QTextStream stream2(fp2);
        QStringList infors1 = stream1.readAll().split('\n');
        QStringList infors2 = stream2.readAll().split('\n');
        for(QString infor:infors2)//存入服务启动类型
        {
            if(infor.contains(".service",Qt::CaseInsensitive))
            {
                QStringList inforss2 = infor.simplified().split(' ');
                if(inforss2[0].contains(".service",Qt::CaseInsensitive))
                    service_start.insert(inforss2.first(),inforss2.last());
                else if(inforss2[1].contains(".service",Qt::CaseInsensitive))
                    service_start.insert(inforss2[1],inforss2.last());
            }
        }
        for(QString infor:infors1)//遍历走完每一服务
        {
            if(infor.contains(".service",Qt::CaseInsensitive))
            {
                QStringList inforss1 = infor.simplified().split(' ');
                if(inforss1[0].contains(".service",Qt::CaseInsensitive))//前面不带'.'分开讨论
                {
                    QString process_cmd="service bluetooth status|grep -v Warning|grep -v ^$";
                    SysServerInfor* item=new SysServerInfor(uint16_t(SecurityToolCode::SysServers));
                    item->_infors[SysServerInfor::SERNAME]=inforss1[0].replace(".service","");
                    if(inforss1[3]=="running")
                        item->_infors[SysServerInfor::STATE]="运行中";
                    else if(inforss1[3]=="exited")
                        item->_infors[SysServerInfor::STATE]="已退出";
                    else if(inforss1[3]=="failed")
                        item->_infors[SysServerInfor::STATE]="启动失败";
                    else
                        item->_infors[SysServerInfor::STATE]=inforss1[3];
                    temp = popen(process_cmd.replace("bluetooth",inforss1[0]).toLocal8Bit(),"r");//获取服务详细信息
                    QTextStream streamtemp(temp);
                    QStringList inforstemp = streamtemp.readAll().split('\n');
                    for(QString infortemp:inforstemp)
                    {
                        if(infortemp.contains(inforss1[0]+".service",Qt::CaseSensitive)&&infortemp[0]=="●")
                        {
                            item->_infors[SysServerInfor::DESCRIPTION]=infortemp.mid(infortemp.indexOf('-')+2);
                        }
                        else if(infortemp.contains("Main PID: ",Qt::CaseSensitive))
                        {
                            PID = infortemp.mid(infortemp.indexOf(':')+1).simplified().split(' ').first();
                                item->_infors[SysServerInfor::PRONAME]=infortemp.mid(infortemp.indexOf('(')+1).replace(")","");

                        }
                        else if(infortemp.contains("─",Qt::CaseSensitive))
                        {
                            if(infortemp.contains(PID))
                            {
                                item->_infors[SysServerInfor::PATH]=infortemp.simplified().mid(infortemp.simplified().indexOf('/'));
                            }
                        }
                    }
                    if(service_start.find(inforss1[0].append(".service"))!=service_start.end())
                    {
                        item->_infors[SysServerInfor::STARTTYPE]="自动启动";
                    }
                    else
                        item->_infors[SysServerInfor::STARTTYPE]="手动启动";
                    if(item->_infors[SysServerInfor::STATE]=="已退出")
                        item->_infors[SysServerInfor::PRONAME]="*服务已退出";
                    if(item->_infors[SysServerInfor::STATE]=="已退出")
                        item->_infors[SysServerInfor::PATH]="*服务已退出";
                    if(item->_infors[SysServerInfor::DESCRIPTION]=="")
                        item->_infors[SysServerInfor::DESCRIPTION]="*";
                    if(item->_infors[SysServerInfor::SIGN]=="")
                        item->_infors[SysServerInfor::SIGN]="*";
                    result.push_back(item);
                }
                else if(inforss1[1].contains(".service",Qt::CaseInsensitive))//前面带'.'
                {
                    QString process_cmd="service bluetooth status|grep -v Warning|grep -v ^$";
                    SysServerInfor* item=new SysServerInfor(uint16_t(SecurityToolCode::SysServers));
                    item->_infors[SysServerInfor::SERNAME]=inforss1[1].replace(".service","");
                    item->_infors[SysServerInfor::STATE]=inforss1[4];
                    if(inforss1[4]=="running")
                        item->_infors[SysServerInfor::STATE]="运行中";
                    else if(inforss1[4]=="exited")
                        item->_infors[SysServerInfor::STATE]="已退出";
                    else if(inforss1[4]=="failed")
                        item->_infors[SysServerInfor::STATE]="启动失败";
                    else
                        item->_infors[SysServerInfor::STATE]=inforss1[4];
                    temp = popen(process_cmd.replace("bluetooth",inforss1[0]).toLocal8Bit(),"r");//获取服务详细信息
                    QTextStream streamtemp(temp);
                    QStringList inforstemp = streamtemp.readAll().split('\n');
                    for(QString infortemp:inforstemp)
                    {
                        if(infortemp.contains(inforss1[1]+".service",Qt::CaseSensitive)&&infortemp=="●")
                        {
                            item->_infors[SysServerInfor::DESCRIPTION]=infortemp.mid(infortemp.indexOf('-')+2);
                        }
                        else if(infortemp.contains("Main PID: ",Qt::CaseSensitive))
                        {
                            PID = infortemp.mid(infortemp.indexOf(':')+1).simplified().split(' ').first();
                            item->_infors[SysServerInfor::PRONAME]=infortemp.mid(infortemp.indexOf('(')+1).replace(")","");
                        }
                        else if(infortemp.contains("─",Qt::CaseSensitive))
                        {
                            if(infortemp.contains(PID))
                            {
                                item->_infors[SysServerInfor::PATH]=infortemp.simplified().mid(infortemp.simplified().indexOf('/'));
                            }
                        }
                    }
                    if(service_start.find(inforss1[1].append(".service"))!=service_start.end())
                    {
                        item->_infors[SysServerInfor::STARTTYPE]="自动启动";
                    }
                    else
                        item->_infors[SysServerInfor::STARTTYPE]="手动启动";

                    if(item->_infors[SysServerInfor::STATE]=="已退出")
                        item->_infors[SysServerInfor::PRONAME]="*服务已退出";
                    if(item->_infors[SysServerInfor::STATE]=="已退出")
                        item->_infors[SysServerInfor::PATH]="*服务已退出";
                    if(item->_infors[SysServerInfor::DESCRIPTION]=="")
                        item->_infors[SysServerInfor::DESCRIPTION]="*";
                    if(item->_infors[SysServerInfor::SIGN]=="")
                        item->_infors[SysServerInfor::SIGN]="*";
                    result.push_back(item);
                }
            }
        }
        return result;
    }

    QVector<BaceInfor*> Reslution::GetSysKernelInforFromCmd()              //系统加载内核
    {
        //安装时间
        //modinfo veth -d,查看描述信息
        #ifdef LINUX
            QString cmd="lsmod|grep -v Module";
            QString modinfor_cmd = "modinfo veth -d";
        #else
            QString cmd="lsmod";
            QString modinfor_cmd = "modinfo veth -d";
        #endif
        QVector<BaceInfor*> result;
        FILE* fp=popen(cmd.toLocal8Bit(),"r");

        if(fp==nullptr)
            return result;
        QTextStream fstream(fp);

        QStringList infors=fstream.readAll().split('\n');
        for(QString infor:infors)
        {
            if(infor=="")
                break;
            QString modinfor_cmd1 = modinfor_cmd;
            SysKernelInfor* temp=new SysKernelInfor(uint16_t(SecurityToolCode::SysKernel));
            QStringList temp1=infor.simplified().split(' ');
            temp->_infors[SysKernelInfor::KERNELNAME]=temp1[0];
            temp->_infors[SysKernelInfor::INSTALLTIME]="未知";                                                                            //bug
            FILE* fp1=popen(modinfor_cmd1.replace("veth",temp1[0]).toLocal8Bit(),"r");
            QTextStream fstream1(fp1);
            temp->_infors[SysKernelInfor::DESCRIP]=fstream1.readLine();
            if(temp->_infors[SysKernelInfor::DESCRIP]=="")
                temp->_infors[SysKernelInfor::DESCRIP]="*";
            result.push_back(temp);
        }
        return result;
    }

    QVector<BaceInfor*> Reslution::GetEmailInforFromCmd()                  //邮件客户端
    {
        QVector<QString> packages={"Thunderbird","evolution","kmail","thunderbird"};//通过包名查找
        QVector<BaceInfor*>result;
        for(QString package:packages)
        {
            QString install_cmd="(grep install /var/log/dpkg.log&&grep install /var/log/dpkg.log.1)|grep \"install ";//查询名称，安装版本信息，安装时间信息
            QString install_route_cmd="whereis ";//查询安装路径
            QString appsize_cmd="du -h ";//查询文件大小
            EmailInfor *temp = new EmailInfor(uint16_t(SecurityToolCode::EmailInfor));
            temp->_infors[EmailInfor::NAME]=package;
            install_cmd = install_cmd + package + "\"";
            FILE *fp = popen(install_cmd.toLocal8Bit(),"r");//开始寻找版本和安装时间信息
            if(fp==nullptr)
                return {};
            QTextStream fstream(fp);
            QStringList infors=fstream.readAll().split('\n');
            if(infors.size()<=1)//过滤不需要的元素
                continue;
            for(QString infor:infors)
            {
                if(infor=="")
                    continue;
                QStringList inforss=infor.simplified().split(' ');
                QStringList inforss1=inforss[3].simplified().split(':');
                if(inforss1[0].contains(package,Qt::CaseInsensitive))
                {
                    temp->_infors[EmailInfor::INSTALLTIME]=inforss[0]+" "+inforss[1];
                    temp->_infors[EmailInfor::VERSION]=inforss.last();
                    break;
                }
            }
            install_route_cmd += package;
            FILE *fp1 = popen(install_route_cmd.toLocal8Bit(),"r");//开始寻找路径
            if(fp1==nullptr)
                return {};
            QTextStream fstream1(fp1);
            QStringList infors1=fstream1.readAll().split('\n');
            for(QString infor:infors1)
            {
                if(infor=="")
                    continue;
                QStringList inforss=infor.simplified().split(' ');
                if(inforss.size()>=2)
                {
                    temp->_infors[EmailInfor::PATH]=inforss[1];
                    appsize_cmd += inforss[1];
                }
                else
                {
                    temp->_infors[EmailInfor::PATH]="未知";
                    temp->_infors[EmailInfor::SIZE]="未知";
                }
            }
            if(temp->_infors[EmailInfor::SIZE]!="未知")
            {
                FILE *fp2 = popen(appsize_cmd.toLocal8Bit(),"r");//开始寻找软件大小
                if(fp2==nullptr)
                    return {};
                QTextStream fstream2(fp2);
                QStringList infors2=fstream2.readAll().split('\n');
                for(QString infor:infors2)
                {
                    if(infor=="")
                        continue;
                    QStringList inforss = infor.simplified().split(' ');
                    temp->_infors[EmailInfor::SIZE]=inforss[0];//bug
                    break;
                }
            }
            result.push_back(temp);
        }
        return result;
    }

    QVector<BaceInfor*> Reslution::GetVirMachineFromCmd()                   //虚拟机安装
    {
        QVector<QString> packages={"virtualbox","vmware"};//通过包名查找
        QVector<BaceInfor*>result;
        for(QString package:packages)
        {
            QString install_cmd="(grep install /var/log/dpkg.log&&grep install /var/log/dpkg.log.1)|grep \"install ";//查询名称，安装版本信息，安装时间信息
            QString install_route_cmd="whereis ";//查询安装路径
            QString appsize_cmd="du -h ";//查询文件大小
            VirMachine *temp = new VirMachine(uint16_t(SecurityToolCode::VirMachine));
            install_cmd = install_cmd + package + "\"";
            FILE *fp = popen(install_cmd.toLocal8Bit(),"r");//开始寻找版本和安装时间信息
            if(fp==nullptr)
                return {};
            QTextStream fstream(fp);
            QStringList infors=fstream.readAll().simplified().split('\n');
            if(infors.first().size() != 0) {
                temp = new VirMachine(uint16_t(SecurityToolCode::VirMachine));
                temp->_infors[VirMachine::ITEMS]="名称：\t"+package;
                result.push_back(temp);
            }
            if(infors.size()<=1)//过滤不需要的元素
                continue;
            for(QString infor:infors)
            {
                if(infor=="")
                    continue;
                QStringList inforss=infor.simplified().split(' ');
                QStringList inforss1=inforss[3].simplified().split(':');
                if(inforss1[0].contains(package,Qt::CaseInsensitive))
                {
                    temp = new VirMachine(uint16_t(SecurityToolCode::VirMachine));
                    temp->_infors[VirMachine::ITEMS]="安装时间：\t"+inforss[0]+" "+inforss[1];
                    result.push_back(temp);
                    temp = new VirMachine(uint16_t(SecurityToolCode::VirMachine));
                    temp->_infors[VirMachine::ITEMS]="版本：\t"+inforss.last();
                    result.push_back(temp);
                    break;
                }
            }
            install_route_cmd += package;
            FILE *fp1 = popen(install_route_cmd.toLocal8Bit(),"r");//开始寻找路径
            if(fp1==nullptr)
                return {};
            QTextStream fstream1(fp1);
            QStringList infors1=fstream1.readAll().split('\n');
            for(QString infor:infors1)
            {
                if(infor=="")
                    continue;
                QStringList inforss=infor.simplified().split(' ');
                if(inforss.size()>=2)
                {
                    temp = new VirMachine(uint16_t(SecurityToolCode::VirMachine));
                    temp->_infors[VirMachine::ITEMS]="路径：\t"+inforss[1];
                    result.push_back(temp);
                    appsize_cmd += inforss[1];
                }
                else
                {
                    temp = new VirMachine(uint16_t(SecurityToolCode::VirMachine));
                    temp->_infors[VirMachine::ITEMS]="路径：\t未知";
                    result.push_back(temp);
                    temp = new VirMachine(uint16_t(SecurityToolCode::VirMachine));
                    temp->_infors[VirMachine::ITEMS]="大小：\t未知";
                    result.push_back(temp);
                }
            }
            if(temp->_infors[VirMachine::ITEMS]!="大小：\t未知")                                                             //###
            {
                FILE *fp2 = popen(appsize_cmd.toLocal8Bit(),"r");//开始寻找软件大小
                if(fp2==nullptr)
                    return {};
                QTextStream fstream2(fp2);
                QStringList infors2=fstream2.readAll().split('\n');
                for(QString infor:infors2)
                {
                    if(infor=="")
                        continue;
                    QStringList inforss = infor.simplified().split(' ');
                    temp = new VirMachine(uint16_t(SecurityToolCode::VirMachine));
                    temp->_infors[VirMachine::ITEMS]="大小：\t"+inforss[0];//bug
                    result.push_back(temp);
                    break;
                }
            }
        }
        return result;
    }

    QVector<BaceInfor*> Reslution::GetDefendSoftFromCmd()                  //杀毒软件防护
    {
        QMap<QString,QString> packages={//软件名称，软件公司,通过包名查找
            {"clamav","Clam Technology Co.Ltd"},
            {"Avast","ALWIL Software"},
            {"Avria","AVIRA"},
            {"AVG","AVGTechnologiesCZ,s.r.o."},
            {"F-PROT","FriskSoftwareInternational"}
        };
        QVector<BaceInfor*>result;
        QMap<QString, QString>::iterator iter = packages.begin();
           while (iter != packages.end())
           {
               QString install_cmd="(grep install /var/log/dpkg.log&&grep install /var/log/dpkg.log.1)|grep ";
               QString update_cmd="(grep upgrape /var/log/dpkg.log&&grep upgrape /var/log/dpkg.log.1)|grep ";
               DefendSoft* temp =  new DefendSoft(uint16_t(SecurityToolCode::DefendSoft));
               install_cmd = install_cmd + "\"" + iter.key() + "\"";
               update_cmd = update_cmd + "\"" + iter.key() + "\"";
               FILE *fp = popen(install_cmd.toLocal8Bit(),"r");//开始寻找版本和安装时间信息
               if(fp==nullptr)
                   return {};
               QTextStream fstream(fp);
               QStringList infors=fstream.readAll().split('\n');
               if(infors.size()<=1)
               {
                   iter++;
                   continue;
               }
               for(QString infor:infors)
               {
                   if(infor=="")
                       continue;
                   QStringList inforss=infor.simplified().split(' ');
                   temp->_infors[DefendSoft::VERSION]=inforss.last();
                   if(inforss.size()>=2)
                       temp->_infors[DefendSoft::INSTALLTIME]=inforss[0]+" "+inforss[1];
                   else
                       temp->_infors[DefendSoft::INSTALLTIME]="未知";
               }
               temp->_infors[DefendSoft::NAME]=iter.key();
               temp->_infors[DefendSoft::COMPANY]=iter.value();
               FILE *fp1 = popen(update_cmd.toLocal8Bit(),"r");//开始寻找更新时间信息
               if(fp1==nullptr)
                   return {};
               QTextStream fstream1(fp1);
               QStringList infors1=fstream1.readAll().split('\n');
               for(QString infor:infors1)
               {
                   if(infor=="")
                       continue;
                   QStringList inforss=infor.simplified().split(' ');
                   if(inforss.size()>=2)
                       temp->_infors[DefendSoft::UPDATETIME]=inforss[0]+" "+inforss[1];
                   else
                       temp->_infors[DefendSoft::UPDATETIME]="未知";
               }
               if(temp->_infors[DefendSoft::UPDATETIME].size()==0)
                   temp->_infors[DefendSoft::UPDATETIME]="未知";
               if(temp->_infors[DefendSoft::INSTALLTIME].size()==0)
                   temp->_infors[DefendSoft::INSTALLTIME]="未知";
               if(temp->_infors[DefendSoft::VERSION].size()==0)
                   temp->_infors[DefendSoft::VERSION]="未知";
               result.push_back(temp);
               fclose(fp);
               fclose(fp1);
               iter++;
           }
        return result;
    }
    QVector<BaceInfor*> Reslution::GetUserLoginInforFromCmd(){
        #ifdef LINUX

                QString cmd="last -i";
        #else
                QString cmd="last -i";
        #endif
        QVector<BaceInfor*> result;
        QStringList infors=Reslution::GetFromString(cmd);

        for(QString& infor:infors)
        {
            QStringList temp=infor.simplified().split(' ');
            if(temp[0]=="reboot")
                continue;
            else if(temp[0]=="")
                break;

            UserLoginInfor* login=new UserLoginInfor(uint16_t(SecurityToolCode::NetLogin));
            login->_infors[UserLoginInfor::USER]=temp[0];    //用户
            login->_infors[UserLoginInfor::TERMINER]=temp[1];
            login->_infors[UserLoginInfor::IPADR]=temp[2];
            if(temp[7]=="-"){
                login->_infors[UserLoginInfor::DATE]=QStringList{temp[3],temp[4],temp[5],temp[6],temp[7],temp[8]}.join(' ');
                temp[9].remove(0,1);
                temp[9].remove(temp[9].size()-1,1);
                login->_infors[UserLoginInfor::RUNTIME]=temp[9];
            }else{
                login->_infors[UserLoginInfor::DATE]=QStringList{temp[3],temp[4],temp[5],temp[6],"-"}.join(' ');
                QString t;
                for(int i=7;i<temp.size();++i)
                    t.append(temp[i]+" ");
                login->_infors[UserLoginInfor::RUNTIME]=t;
            }

            if(temp[2]!="0.0.0.0")
                login->_infors[UserLoginInfor::RESULT]="外部登陆";
            else
                login->_infors[UserLoginInfor::RESULT]="内部登陆";

            result.push_back(login);
        }
        return result;
    }


    QVector<BaceInfor*> Reslution::GetBroHistoryInforFromCmd()
    {
    #ifdef LINUX
    //        QString cmd1="ls /home/";
        QString cmd2="cp /home/%1/.config/browser/Default/History ./";
    //      QString cmd2="cp /home/%1/.config/browser/Default/encrypted/History ./";
    #endif

        QVector<BaceInfor*> result;
        QStringList users;

        users.push_back(QHostInfo::localHostName());

        for(QString& user:users){
            QString cmd=cmd2.arg(user);
            Reslution::ExecuteCmd(cmd);

            DataBaseTool::qmutex.lock();

            DataBaseTool::GetInsatnce()->SetDataBaseName("History");
            DataBaseTool::GetInsatnce()->Execute("select * from urls");
            QVector<QStringList>&& infors=DataBaseTool::GetInsatnce()->GetResult();

            DataBaseTool::qmutex.unlock();

            for(QStringList& infor:infors){
               WebHistoryInfor* ret=new WebHistoryInfor(uint16_t(SecurityToolCode::BroHistory));
               ret->_infors[WebHistoryInfor::URL]=infor[1];
               ret->_infors[WebHistoryInfor::TITLE]=infor[2];
               ret->_infors[WebHistoryInfor::LOGNMS]=infor[3];
               ret->_infors[WebHistoryInfor::LOGTIME]=infor[5];
               ret->_infors[WebHistoryInfor::USER]=user;

               result.push_back(ret);
            }
        }

        return result;
    }


    QVector<BaceInfor*> Reslution::GetBroDownloadInforFromCmd()
    {
        return {};
    }

    QVector<BaceInfor*> Reslution::GetBroCollectInforFromCmd()
    {
    #ifdef LINUX
        QString cmd2=tr("cp /home/%1/.config/browser/Default/Top\\ Sites ./top_sites");
    #endif

        QVector<BaceInfor*> result;
        cmd2=cmd2.arg(QHostInfo::localHostName());
        Reslution::ExecuteCmd(cmd2);

        DataBaseTool::qmutex.lock();

        DataBaseTool::GetInsatnce()->SetDataBaseName(tr("top_sites"));
        DataBaseTool::GetInsatnce()->Execute("select * from top_sites");
        QVector<QStringList>&& infors=DataBaseTool::GetInsatnce()->GetResult();

        DataBaseTool::qmutex.unlock();

        for(QStringList& infor:infors){
           WebCollect* ret=new WebCollect(uint16_t(SecurityToolCode::BroCollect));
           ret->_infors[WebCollect::URL]=infor[0];
           ret->_infors[WebCollect::TITLE]=infor[2];
           ret->_infors[WebCollect::USER]=QHostInfo::localHostName();
           result.push_back(ret);
        }
        return result;
    }

    QVector<BaceInfor*> Reslution::GetBroCookiesInforFromCmd(){
    #ifdef LINUX
        QString cmd2="cp /home/%1/.config/browser/Default/Cookies ./";
    //     QString cmd2="cp /home/%1/.config/browser/Default/encrypted/Cookies ./";
  //      QString cmd2="cp /home/%1/.config/browser/Default/Safe\\ Browsing\\ Cookies ./Cookies";

    #endif

        QVector<BaceInfor*> result;
        cmd2=cmd2.arg(QHostInfo::localHostName());
        Reslution::ExecuteCmd(cmd2);

        DataBaseTool::qmutex.lock();

        DataBaseTool::GetInsatnce()->SetDataBaseName("Cookies");
        DataBaseTool::GetInsatnce()->Execute("select * from cookies");
        QVector<QStringList>&& infors=DataBaseTool::GetInsatnce()->GetResult();

        DataBaseTool::qmutex.unlock();

        for(QStringList& infor:infors){
           WebCookiesInfor* ret=new WebCookiesInfor(uint16_t(SecurityToolCode::BroHistory));
           ret->_infors[WebCookiesInfor::TIME]=infor[0];
           ret->_infors[WebCookiesInfor::URL]=infor[1];
           ret->_infors[WebCookiesInfor::PATH]=infor[4];
           ret->_infors[WebCookiesInfor::NAME]=infor[2];
           ret->_infors[WebCookiesInfor::USER]=QHostInfo::localHostName();
           result.push_back(ret);
        }
        return result;
    }

    QVector<BaceInfor*> Reslution::GetSoftListFromCmd(){
    #ifdef LINUX
        QString cmd1="cat /var/log/dpkg.log /var/log/dpkg.log.1|grep ' installed '";
        QString cmd2="zcat /var/log/dpkg.log.2.gz /var/log/dpkg.log.3.gz|grep ' installed '";
        QString cmd3="sudo dpkg -l|grep ^ii";//获取描述信息
    #endif

        QVector<BaceInfor*> res;
        QStringList infors1=Reslution::GetFromString(cmd1);
        QStringList infors2=Reslution::GetFromString(cmd2);
        QStringList infors3=Reslution::GetFromString(cmd3);
        QMap<QString,QString> describes;//存入描述信息
        for(QString temp:infors3) {
            QStringList infor = temp.simplified().split(' ');
            QString key = infor.value(1).split(':').first();
            QString value = "";
            if(infor.size() > 4) {
                for(int i = 4; i< infor.size(); i++) {
                    value.append(infor[i]+' ');
                }
            }
            describes.insert(key,value);
        }

        for(QString temp:infors1+infors2){
            QStringList keys=temp.split(' ');
            if(keys.size()<3)   continue;
            if(keys[2]!="status")    continue;
            Yzty::SystemSoftList* infor=new Yzty::SystemSoftList(uint16_t(NormalToolCode::SoftLists));

            infor->_infors[SystemSoftList::Time]=keys[0]+" "+keys[1];       //安装时间
            QStringList tp4=keys[4].split(':');
            infor->_infors[SystemSoftList::Name]=tp4[0];
            if(tp4.size()>1)
            infor->_infors[SystemSoftList::Struct]=tp4[1];
            infor->_infors[SystemSoftList::Version]=keys[5];
            infor->_descripe = describes[tp4[0]];
            res.push_back(infor);
        }
        return  res;
    }

};
